﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading;

namespace arcsoft_usb_video.Utils
{
    class VideoNewFrame
    {
        private object sync = new object();
        private Bitmap currentFrame;
        public void Vcd_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs)
        {
            lock (sync)
            {
                if(currentFrame != null)
                {
                    currentFrame.Dispose();
                    currentFrame = null;
                }
                currentFrame = (Bitmap)eventArgs.Frame.Clone();
                currentFrame.RotateFlip(RotateFlipType.Rotate180FlipY);
            }
        }

        public Bitmap Get_NewFrame()
        {
            lock (sync)
            {
                return (currentFrame == null) ? null : AForge.Imaging.Image.Clone(currentFrame);
            }
        }

    }
}
